/*
 * main.cpp
 *
 *  Created on: 2011-03-30
 *      Author: jacek
 */
#include "Event.h"
#include "Object.h"
#include "Component.h"
#include "NetSender.h"
#include "NetUDPReceiver.h"
#include <iostream>
using namespace std;

class ClientOut:public Component{
public:
	ClientOut(){}
	virtual void Updata(Event event) {

	}
	virtual void Intialization() {

	}
	virtual void Dispose() {


	}
	virtual void SendEvent(Event event) {
		//TODO Nie wyswietla otrzymanej paczki. Chyba ja dostaje bo przestaje czekac na nia..
		cout << "Receive package " << sizeof(event) << " bytes, destination="
				<< event.destination << " sender=" << event.sender << " type="
				<< event.type << endl;
	}
	~ClientOut() {

	}
}out;

int main(int argc, char **argv) {
	try {

		NetAddress server;

		Socket sock;
		sock.CreateSendingSocket(Socket::UDP);
		server.SetAddress("127.0.0.1", 50002);
		sock.Connect(server);
		NetSender sender(sock);


		Socket sockR;
		server.SetAddress("127.0.0.1", 50003);
		sockR.CreateUDPRecevSocket(server);
		NetUDPReceiver reciever(sockR);


		Object Ogre(0);
		Ogre.mainParent=&out;
		Ogre.RegisterComponent(&sender);
		Ogre.RegisterComponent(&reciever);
		Ogre.Intialization();
		Event event;
		event.type = NET_E;
		event.sender = 0;
		event.destination = 1000;
		cout <<"Send package "<< sizeof(Event) << " Type: " << event.type << " Sender: "
				<< event.sender << " Destination: " << event.destination
				<< endl;
		Ogre.Updata(event);
		event.type = NET_RECV;
		event.sender = 0;
		event.destination = 0;
		Ogre.Updata(event);
		Ogre.Dispose();
		sock.Close();

	} catch (SocketException e) {
		cout << e.GetMessage();
	}

	return 0;
}
